#####################################################################
# Product:      KnowledgeEngine (Plone Edition)
#
# File:         WizardStepDefinition.py
#
# Copyright:    Copyright (c) 2005, Faulkner Technologies
#
# Author:       Brian Oliver
#
# Description:  A WizardStepDefinition instance encapsulates the property 
#               definitions for a Wizard.  WizardStepDefinitions simplifies
#               defining wizard properties for each step in a Wizard, the
#               drawback being the steps become 'static' in that the
#               properties can't easily change at runtime.
#
#               To implement 'dynamic' properties in a wizard step
#               override the 'getWizardStepProperties' method in
#               your subclass of Wizard.
#
# See Also:     Wizard, WizardState, PropertyDefinition
#####################################################################

#####################################################################
## KnowledgeEngine Library Imports
from Common import *

#####################################################################
## Zope Library Imports
from Globals import InitializeClass
from AccessControl import ClassSecurityInfo
from AccessControl.Role import RoleManager
 
#####################################################################
## Python Library Imports
# (none)
    
#####################################################################
## WizardStepDefinition Class Definition
class WizardStepDefinition(RoleManager):
    """
        An object to represent a collection of property definitions
        for a Wizard Step.
    """
        
    #---------------------------------------------------------------#

    #declare security so ClassInfo may be accessed in DTML/ZPT etc
    security = ClassSecurityInfo()
    security.declareObjectPublic()
    security.setDefaultAccess("allow")

    #---------------------------------------------------------------#

    def __init__(self, title, description, propertyDefinitions = []):
        """
            WizardStepDefinition constructor.
            
            PARAMETERS:
            propertyDefinitions: A list of PropertyDefinition in the order
                                 in which the properties should appear
                                 in a Wizard Step.
        """
        
        self.title = title
        self.description = description      
        self.propertyDefinitionsById = {}
        self.propertyDefinitionsByOrder = propertyDefinitions
        for propertyDefinition in propertyDefinitions:
            self.propertyDefinitionsById[propertyDefinition.getIdentity()] = propertyDefinition

    #---------------------------------------------------------------#

    def getTitle(self):
        """
            Return the title for the wizard step
        """
        
        return self.title

    #---------------------------------------------------------------#

    def getDescription(self):
        """
            Return the description for the wizard step
        """
        
        return self.description

    #---------------------------------------------------------------#

    def getPropertyDefinitions(self):
        """
            Return the property definitions for the wizard step
        """
        
        return self.propertyDefinitionsByOrder

    #---------------------------------------------------------------#

    def addPropertyDefinition(self, propertyDefinition):
        """
            Return the property definitions for the wizard step
        """
        
        self.propertyDefinitionsById[propertyDefinition.getIdentity()] = propertyDefinition
        self.propertyDefinitionsByOrder = self.propertyDefinitionsByOrder + [propertyDefinition]
        
    #---------------------------------------------------------------#
        
#####################################################################
## Class Initialisation
InitializeClass(WizardStepDefinition)
